# Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
# Copyright 2015, Daniel Axtens, IBM Corporation
# zlib license, see zlib.h

CC=
CFLAGS=
EXE=
SRCDIR=
SRCTOP=
INCLUDES=
TEST_LDFLAGS=-L.. ../libz.a

COMPATTESTS =

all: oldtests cvetests $(COMPATTESTS)

oldtests: #set by ../configure

teststatic:
	@TMPST=tmpst_$$; \
	if echo hello world | ../minigzip | ../minigzip -d && ../example $$TMPST ; then \
	  echo '		*** zlib test OK ***'; \
	else \
	  echo '		*** zlib test FAILED ***'; exit 1; \
	fi; \
	rm -f $$TMPST

testshared:
	@LD_LIBRARY_PATH=`pwd`/..:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
	LD_LIBRARYN32_PATH=`pwd`/..:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
	DYLD_LIBRARY_PATH=`pwd`/..:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
	SHLIB_PATH=`pwd`/..:$(SHLIB_PATH) ; export SHLIB_PATH; \
	TMPSH=tmpsh_$$; \
	if echo hello world | ../minigzipsh | ../minigzipsh -d && ../examplesh $$TMPSH; then \
	  echo '		*** zlib shared test OK ***'; \
	else \
	  echo '		*** zlib shared test FAILED ***'; exit 1; \
	fi; \
	rm -f $$TMPSH

test64:
	@TMP64=tmp64_$$; \
	if echo hello world | ../minigzip64 | ../minigzip64 -d && ../example64 $$TMP64; then \
	  echo '		*** zlib 64-bit test OK ***'; \
	else \
	  echo '		*** zlib 64-bit test FAILED ***'; exit 1; \
	fi; \
	rm -f $$TMP64

cvetests: testCVEinputs

# Tests requiring zlib-ng to be built with --zlib-compat
compattests: testCVE-2003-0107

testCVEinputs:
	@$(SRCDIR)/testCVEinputs.sh

testCVE-2003-0107: CVE-2003-0107$(EXE)
	@if ./CVE-2003-0107$(EXE); then \
	  echo '                *** zlib not vulnerable to CVE-2003-0107 ***'; \
	else \
	  echo '                *** zlib VULNERABLE to CVE-2003-0107 ***'; exit 1; \
	fi

CVE-2003-0107.o: $(SRCDIR)/CVE-2003-0107.c
	$(CC) $(CFLAGS) -I.. -I$(SRCTOP) -c -o $@ $(SRCDIR)/CVE-2003-0107.c

CVE-2003-0107$(EXE): CVE-2003-0107.o
	$(CC) $(CFLAGS) -o $@ CVE-2003-0107.o $(TEST_LDFLAGS)


clean:
	rm -f *.o *.gcda *.gcno *.gcov
	rm -f CVE-2003-0107$(EXE)

distclean:
	rm -f Makefile
